import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('user', () => {
  const userId = ref(localStorage.getItem('userId') || '')
  const userInfo = ref(null)

  const setUserId = (newUserId) => {
    userId.value = newUserId
    localStorage.setItem('userId', newUserId)
  }

  const setUserInfo = (info) => {
    userInfo.value = info
  }

  const logout = () => {
    userId.value = ''
    userInfo.value = null
    localStorage.removeItem('userId')
  }

  const isAuthenticated = () => {
    return !!userId.value
  }

  return {
    userId,
    userInfo,
    setUserId,
    setUserInfo,
    logout,
    isAuthenticated
  }
}) 